home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Source / xpkmaster / debug.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-12  |  3.3 KB  |  143 lines

  1. #ifndef XPKMASTER_DEBUF_C
  2. #define XPKMASTER_DEBUG_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        debug.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: debug.c 1.6 (12.04.97)
  9.     Author:        SDI
  10.     Distribution:    PD
  11.     Description:    the debug stuff
  12.  
  13.  1.0   05.10.96 : first real version
  14.  1.1   20.10.96 : added the external debug modes
  15.  1.2   21.10.96 : changed debug totally
  16.  1.3   01.01.97 : changed output a bit - "XpkM before stuff - find in lots
  17.      of other debuf stuff"
  18.  1.4   09.03.97 : output contained 0 byte - removed
  19.  1.5   01.04.97 : little changes
  20.  1.6   12.04.97 : added TagList output, therefor changed XPKDEBUG contents
  21. */
  22.  
  23. #include <exec/types.h>
  24. #include <pragma/exec_lib.h>
  25. #include <pragma/dos_lib.h>
  26. #include <pragma/utility_lib.h>
  27. #include <utility/tagitem.h>
  28. #include <dos/var.h>
  29. #include <xpk/xpk.h>
  30.  
  31. extern struct Library *UtilityBase;
  32.  
  33. typedef void (*putchtype) ();
  34.  
  35. #ifdef __MAXON__
  36.   #define __asm
  37. #endif
  38.  
  39. #define FLAG_ERROR    (1<<0)
  40. #define FLAG_RUNTIME    (1<<1)
  41. #define FLAG_TAGLIST    (1<<2)
  42.  
  43. extern KPutChar(LONG);
  44. extern DPutChar(LONG);
  45. extern struct DosLibrary *DOSBase;
  46. extern void DoDebug(UBYTE mode, STRPTR fmt, APTR data);
  47.  
  48. static void __asm serfunc(register __d0 UBYTE c, register __a3 ULONG pd)
  49. { if(c) KPutChar(c); }
  50.  
  51. static void __asm parfunc(register __d0 UBYTE c, register __a3 ULONG pd)
  52. { if(c) DPutChar(c); }
  53.  
  54. static void __asm normfunc(register __d0 UBYTE c, register __a3 ULONG pd)
  55. {
  56.   UBYTE d = c;
  57.   if(c)
  58.     Write(pd, &d, 1);
  59. }
  60.  
  61. void DebugTagList(STRPTR fmt, struct TagItem *taglist)
  62. {
  63.   DoDebug(FLAG_TAGLIST, fmt, taglist);
  64. }
  65.  
  66. void DebugError(STRPTR format, ...)
  67. {
  68.   DoDebug(FLAG_RUNTIME, format, (APTR)((ULONG)(&format)+sizeof(STRPTR)));
  69. }
  70.  
  71. void DebugRunTime(STRPTR format, ...)
  72. {
  73.   DoDebug(FLAG_ERROR, format, (APTR)((ULONG)(&format)+sizeof(STRPTR)));
  74. }
  75.  
  76. void DoDebug(UBYTE mode, STRPTR fmt, APTR data)
  77. {
  78.   ULONG fh = 0, i, Flags = 0;
  79.   UBYTE Mode[5] = "";
  80.   void __asm (*function)(register __d0 UBYTE, register __a3 ULONG) = 0;
  81.  
  82.   Forbid();
  83.  
  84.   GetVar("XPKDEBUG", (STRPTR) &Mode, 5, GVF_GLOBAL_ONLY);
  85.  
  86.   for(i=1; Mode[i] && i < 5; ++i)
  87.   {
  88.     switch(Mode[i])
  89.     {
  90.       case 'E': Flags |= FLAG_ERROR; break;
  91.       case 'R': Flags |= FLAG_RUNTIME; break;
  92.       case 'T': Flags |= FLAG_TAGLIST; break;
  93.     }
  94.   }
  95.  
  96.   mode &= Flags;
  97.  
  98.   if(mode)
  99.   {
  100.     switch(Mode[0])
  101.     {
  102.     case 'S': function = serfunc; break;
  103.     case 'P': function = parfunc; break;
  104.     case 'F':
  105.       if((fh = Open("T:XpkMasterOut", MODE_READWRITE)))
  106.       {
  107.         Seek(fh, 0, OFFSET_END);
  108.         function = normfunc;
  109.       }
  110.       break;
  111.     }
  112.     if(function)
  113.     {
  114.       i = (ULONG) FindTask(0);
  115.       RawDoFmt("XpkM(%08lx):", &i, (putchtype) function, (APTR) fh);
  116.  
  117.       RawDoFmt(fmt, data, (putchtype) function, (APTR) fh);
  118.       RawDoFmt("\n", 0, (putchtype) function, (APTR) fh);
  119.  
  120.       if(mode & FLAG_TAGLIST)
  121.       {
  122.         struct TagItem *ti;
  123.         while((ti = NextTagItem((struct TagItem **) &data)))
  124.         {
  125.           RawDoFmt("   %08lx, %lu", ti, (putchtype) function, (APTR) fh);
  126.           if((ti->ti_Tag == XPK_InName) || (ti->ti_Tag == XPK_OutName) ||
  127.           (ti->ti_Tag == XPK_FileName) || (ti->ti_Tag == XPK_Password) ||
  128.           (ti->ti_Tag == XPK_PackMethod))
  129.             RawDoFmt(" (%s)", &ti->ti_Data, (putchtype) function, (APTR) fh);
  130.           RawDoFmt("\n", 0, (putchtype) function, (APTR) fh);
  131.         }
  132.       }
  133.     }
  134.  
  135.     if(fh)
  136.       Close(fh);
  137.   }
  138.  
  139.   Permit();
  140. }
  141.  
  142. #endif /* XPKMASTER_DEBUG_C */
  143.